﻿<!DOCTYPE html>

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>采购打码</title>
    <meta name="renderer" content=padding>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/js/layui/css/layui.css" rel="stylesheet" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    @* <script src="~/js/layui/layui.js"></script> *@
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/Scripts/formSelect/multiSelect.js"></script>
    <script type="text/html" id="barDemo">
        @* <a title="查看" href="javascript:;"  lay-event="view" ><i class="layui-icon">&#xe615;</i></a> *@
        <a title="打码" href="javascript:;"  lay-event="print" ><i class="layui-icon">&#xe66d;</i></a>
        @* <a title="完成" href="javascript:;" lay-event="complete" ><i class="layui-icon">&#x1005;</i></a> *@
    </script>
</head>
<body>
    <div class="layui-fluid" style="width:100%;">
        <div id="bDiv">
        </div>
        <div style="float:left;width:100%;">
            <div class="layui-card">

                <div class="layui-card-body" style="margin-top:5px">
                    <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="cCode" placeholder="采购入库单号" autocomplete="off" class="layui-input" id="cCode">
                        </div>
                        @* <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="erpOrder" placeholder="订单编码" autocomplete="off" class="layui-input" id="erpOrder">
                        </div> *@
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="cInvCode" placeholder="存货编码" autocomplete="off" class="layui-input" id="cInvCode">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="cInvName" placeholder="存货名称" autocomplete="off" class="layui-input" id="cInvName">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="cInvStd" placeholder="存货规格" autocomplete="off" class="layui-input" id="cInvStd">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="cVenName" placeholder="供应商" autocomplete="off" class="layui-input" id="cVenName">
                        </div>

                    </form>
                </div>


                <div class="layui-card-body layui-table-body layui-table-main" id="layui-table-main">
                    <table class="layui-hide" id="list" lay-filter="list"></table>
                </div>
            </div>


        </div>
    </div>
</body>
</html>
<script src="~/js/framework/sysframework.js"></script>
<script src="~/js/framework/commonjs.js"></script>
<script src="~/js/sysweb/planjs.js"></script>
<script>
    var webCode = "";

    var selectList = new Array();

    $(function () {
        webCode = getUrlVariable("menuCode");
        BannerData(webCode, "bDiv");
        DictionaryDropDown("pst", "status", "", true);
        loadData();
    })
    function openQueryWin() {
        gjQuery = true;
        InfoOpenPage("../System/QueryWeb?webCode=" + webCode, "高级检索", "85%", "80%");
    }
    function openWin() {
        InfoOpenPage("../Plan/UpdatePlanNew?dataId=0", "创建计划", "85%", "80%", true);
    }


    layui.use(['multiSelect'], function () {
        var $ = layui.jquery, form = layui.form, multiSelect = layui.multiSelect;
    });
    /**
     * 获取多选的状态
     */
    function GetSelectMore() {
        var vals = [],
            texts = [];
        $('select[multiple] option:selected').each(function () {
            vals.push($(this).val());
            texts.push($(this).text());
        })
        $("input[ name='cStatus']").val(vals.join(','));

    }

    var dUrl = "../Bar/getDataList?dataType=purchasePrint&condition=";
    /**
     * 加载数据
     * **/
    function loadData() {
        GetSelectMore();

        if (!gjQuery) {
            qStr = FormToJson("qForm");
        }

        gjQuery = false;
        layui.use('table', function () {
            var conditon = JSON.stringify(qStr);
            var table = layui.table;
            if (conditon.includes("#")) {
                conditon = conditon.replace(/\#/g, "%23");
            }
            table.render({
                elem: '#list'
                , height: 'full-200'   //固定高度-即固定表头固定第一行首行
                , cols: [[ //标题栏
                    // { type: 'checkbox' },
                    { field: 'cCode', align: 'center', title: '采购入库单号', width: 120, sort: true }
                    , { field: 'dDate', align: 'center', title: '单据日期', width: 120 }
                    , { field: 'cVenName', align: 'center', title: '供应商', width: 230 }
                    , { field: 'cInvCode', align: 'center', title: '存货编码', width: 120 }
                    , { field: 'cInvName', align: 'center', title: '存货名称', width: 170 }
                    , { field: 'cInvStd', align: 'center', title: '规格', width: 100 }
                    , {
                        field: 'iUnitCost', align: 'center', title: '单价', width: 120, templet: function (row) {
                            return TwoDecimalPlaces(row.iUnitCost);
                        }
                    }
                    , {
                        field: 'iQuantity', align: 'center', title: '数量', width: 120, templet: function (row) {
                            return TwoDecimalPlaces(row.iQuantity);
                        }
                    }
                    , {
                        field: 'iPrice', align: 'center', title: '金额', width: 120, templet: function (row) {
                            return TwoDecimalPlaces(row.iPrice);
                        }
                    }
                    , { field: 'cWhName', align: 'center', title: '仓库', width: 120 }
                    , { field: 'cBatch', align: 'center', title: '批号', width: 120 }
                    , { field: 'barNum', align: 'center', title: '已打印数量', width: 120 }

                    , { field: 'right', align: 'center', title: '数据操作', toolbar: '#barDemo', width: 90, fixed: 'right' }
                ]], done: function (res, curr, count) {
                    // $("[data-field='id']").css('display', 'none');//隐藏列
                    currPage = curr;
                    TablePowerHide();
                    $.each(res['data'], function (i, j) {
                        if (j['status'] == "ps-finish") {
                            TableRowColor('layui-table-main', i, '#C3FDB8');
                        }
                    });
                }
                , url: dUrl + conditon
                , skin: 'row' //表格风格
                , even: true
                , page: true //是否显示分页
                , limits: [20, 25, 30]
                , limit: 20 //每页默认显示的数量
                , id: "list"
            });
            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data;
                if (obj.event == 'del') {
                    if (data.status != "ps-pg-set" && data.status != "ps-gy-set") {
                        layer.msg('计划此状态禁止删除'); return;
                    }
                    if (data.status == "ps-doing") {
                        layer.msg('计划已派工，禁止删除'); return;
                    }
                    layer.confirm('确认要删除该数据？', function (index) {
                        var info = DelData(data.plCode);
                        if (info.result) {
                            layer.msg("删除成功");
                            obj.del();
                        } else {
                            layer.msg(info.message);
                        }
                        layer.close(index);
                    });
                }
                else if (obj.event == 'edit') {
                    if (data.status == "ps-doing") {
                        layer.msg('计划已派工，禁止修改'); return;
                    }
                    if (data.status == "ps-finish") {
                        layer.msg('计划已完工，禁止修改'); return;
                    }
                    var webUrl = "../Plan/UpdatePlanNew?dataId=" + data.plCode;
                    var title = data.plCode + "-计划修改";
                    NewOpenPage(webUrl, title, "95%", "90%", "list", currPage, dUrl);
                }
                else if (obj.event == 'setGy') {
                    var webUrl = "../Plan/PlanProcess?plCode=" + data.plCode + "&read=0&proCode=" + data.proCode + "&proName=" + data.proName;
                    var title = data.plCode + "-计划工艺";
                    NewOpenPage(webUrl, title, "95%", "90%", "list", currPage, dUrl);
                }
                // 查看
                else if (obj.event == "view") {

                }
                // 打印
                else if (obj.event == "print") {
                    var printUrl = "printBarTools://";

                    const full = location.protocol + '//' + location.host;

                    $.ajax({
                        url: "../Base/GetLoginUser",
                        dataType: "json",
                        type: "POST",
                        async: false,
                        success: function (rsl) {
                            if (rsl.result) {
                                var userStr = rsl.data;
                                var user = JSON.parse(userStr);
                                console.log("获取用户信息：");
                                console.log(user);

                                console.log(user["userCode"]);
                                console.log(user.baseCode);

                                var query = {
                                    type: "purchasePrint",
                                    serverUrl: full,
                                    logLevel: 'none', // info,warn,error
                                    baseCode: user.baseCode,
                                    userCode: user.userCode,

                                    cWhCode: data.cWhCode,
                                    cCode: data.cCode,
                                    cVenCode: data.cVenCode,
                                    dDate: data.dDate,
                                    cInvCode: data.cInvCode,
                                    iQuantity: data.iQuantity,
                                    iUnitCost: data.iUnitCost,
                                    iPrice: data.iPrice,
                                    cWhName: data.cWhName,
                                    cVenName: data.cVenName,
                                    cInvName: data.cInvName,
                                    cInvStd: data.cInvStd,
                                    irowno: data.irowno,
                                    cBatch: data.cBatch,
                                    unitName: data.unitName,
                                    unit: data.unit,
                                };

                                // console.log('启动客户端信息：');
                                // console.log(query);
                                window.location.href = printUrl + JSON.stringify(query);

                            } else {
                                layer.msg(info.message);
                            }
                        }
                    });

                }
                // 完成
                else if (obj.event == "complete") {

                }
            });

        });

    }

    var qStr = "";
    /**
     * 获取高级查询字符串
     * **/
    function GetQueryPar(queryStr) {
        qStr = queryStr;
        loadData();
    }

    function TwoDecimalPlaces(number) {
        return parseFloat(number).toFixed(2);
    }


</script>
